package com.garen.sys.dao.impl;

import com.garen.sys.dao.IFireUserDao;
import com.garen.sys.entity.FireUser;
import com.garen.utils.MapBuilder;
import com.garen.common.BaseDao;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;


@Repository
public class FireUserDaoImpl extends BaseDao<FireUser> implements IFireUserDao {

	@PostConstruct
	private void init(){
		initOrm(FireUser.class);
	}

	/*验证登录帐号是否重复
	 * 即登录帐号记录数 > 0
	 * */
	@Override
	public int checkLoginName(Integer id,String loginName) {
		String sql = "select count(1) from fire_user t where t.user_login_name=:loginName ";
		if(id != null) sql += " and t.user_id <> :id";
		Map<String,Object> paramMap = new MapBuilder()
				.put("loginName", loginName)
				.put("id", id)
				.build();
		return queryForInt(sql, paramMap);
	}

	@Override
	public List<Map<String, Object>> getcountandduty(String org_id) {
		// TODO Auto-generated method stub
		String sql = "select (select count(*)  from fire_duty where fire_org=:fire_org and to_days(fire_create_date) = to_days(now())) as dutycount  , (select count(*) from fire_user where user_org_id=:fire_org) as usercount,(SELECT count(*) from fire_case_record where fire_org=:fire_org and to_days(fire_date) = to_days(now())) as zdcount" ;
		Map<String,Object> paramMap = new MapBuilder()
				 .put("fire_org",org_id)
				 .build();
		List<Map<String,Object>> list=queryForListMap(sql,paramMap);
		return list;
	}
	
}
